public class MaxArea {
    // leetcode hot 100 盛最多水的容器
    // https://leetcode.cn/problems/container-with-most-water/description/?envType=study-plan-v2&envId=top-100-liked
    public int maxArea(int[] height) {
        // 双指针，left从0开始向后移动，right从height.length-1开始向做移动
        // left和right每移动一次就需要计算出对应的容量，然后保留left、right中较高的边
        // 另一边就继续移动
        int left = 0, right = height.length - 1;
        int max = 0;
        while (left < right) {
            int area = Math.min(height[left],height[right]) * (right - left);
            max = Math.max(max, area);
            if (height[left] < height[right]) left++;
            else right--;
        }
        return max;
    }
}
